﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace ConfigServices
{
    public class IniFileConfigService : IConfigService
    {
        public string FilePath { get; set; }
        public string? GetConfig(string key)
        {
            var kv = File.ReadAllLines(FilePath).Select(s => s.Split('=')).Select(arr => new { Key = arr[0], Value = arr[1] })
                .SingleOrDefault(kv => kv.Key == key);

            if (kv == null)
                return null;
            return kv.Value;
            //return kv?.Value;

            //return File.ReadAllLines(FilePath).Select(s=>s.Split('=')).Select(arr=>new { Key=arr[0], Value=arr[1]})
            //    .ToDictionary(kv=>kv.Key, kv => kv.Value)[key];

        }
    }
}
